<template>
  <div id="index">
    <div id="index-menu">
      <Menu></Menu>
    </div>
    <div class="header">
      <Header></Header>
    </div>
    <div id="index-content">
      <router-view></router-view>
    </div>
  </div>
</template>

<script>
import Menu from "@/views/components/menu/menu";
import Header from "@/views/components/header/header";
import { mapActions } from 'vuex'
import { LoginAllPermission, Code } from '@/axios/api'
export default {
  name: '',
  data() {
    return {

    }
  },
  props: [],

  created() {
    var user = window.sessionStorage.getItem('user') ? JSON.parse(window.sessionStorage.getItem('user')) : '';
    if (!user) {
      this.$message.error("请先登录");
      this.$router.push({ name: 'login' })
    }

    var obj = {};
    if (user.data.deptId == 6) {
      obj.workOrderPoolExport = true//工单池-导出
      obj.workOrderSearchExport = true//工单查询-导出
    }
    var list = (user.data.roles.slice())[0].menus

    list.forEach((v) => {
      if (v.menuId == 11) {//工单查询
        obj.workOrderSearch = true
      } if (v.menuId == 10) {//工单池
        obj.workOrderPool = true
      } if (v.menuId == 4) {//增加用户
        obj.addUser = true
      } if (v.menuId == 7) {//工单池-导出
        obj.workOrderPoolExport = true
      } if (v.menuId == 16) {//工单查询-导出
        obj.workOrderSearchExport = true
      } if (v.menuId == 15) {//导入节点分类
        obj.importClassification = true
      } if (v.menuId == 6) {//用户列表
        obj.userList = true
      } if (v.menuId == 19) {//未释放工单
        obj.releaseOrder = true
      } if (v.menuId == 20) {
        obj.cityArea = true //省市区节点管理
      }

    })
    this.SETPERMISSIONCONTROL(obj)
    this.SETUSER(user.data)
  },
  mounted() {
    // this.createdWebsocket({userName:'测试'})
  },
  methods: {
    ...mapActions(['SETPERMISSIONCONTROL', 'SETUSER']),
    createdWebsocket() {
      var that = this;
      //websocket
      var socket;
      if (!window.WebSocket) {
        window.WebSocket = window.MozWebSocket;
      }
      //收消息
      if (window.WebSocket) {
        var str = '测试'
        socket = new WebSocket(`ws://192.168.2.27:4565/ws?userName=${str}`);//ws://127.0.0.1:4565/ws?userName=测试
        socket.onmessage = function (event) {
          // 服务器发给我的消息在这里接收
          console.log(event, 'socket发过来的消息')
        };
        //发送消息
        socket.onopen = function (event) {
          var message = { "userName": '测试' };
          console.log(JSON.parse(JSON.stringify(message)), 'message')
          socket.send(JSON.stringify(message));
          // alert("socket初始化连接完成")
        }
        socket.onclose = function (event) {
          var message = { a: 1 };
          socket.send(JSON.stringify(message));
        }
      } else {
        alert("你的浏览器不支持Websocket");
      }
      function send(message) {
        if (!window.WebSocket) {
          return;
        }
        if (socket.readyState == WebSocket.OPEN) {
          socket.send(message);
        } else {
          alert("连接没有开启");
        }
      }
    }
  },
  components: {
    Header,
    Menu
  },
  computed: {

  },
  watch: {

  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang='scss' scoped>
#index {
  .header {
  }

  #index-menu {
  }

  #index-content {
    margin-left: 200px;
    min-width: 980px;
    max-width: 1450px;
  }
}
</style>
